package com.hust360.percent.pojo;

import android.content.ContentValues;
import android.database.Cursor;

import com.hust360.percent.PercentApplication;
import com.hust360.percent.pojo.Brandlike.BrandlikeDAO;

public class BrandlikeDAOImpl implements BrandlikeDAO {

	@Override
	public void save(Brandlike like) {
		ContentValues values = new ContentValues();
		values.put(Brandlike.BRANDID, like.brandId);
		values.put(Brandlike.ID, like.id);
		values.put(Brandlike.UID, like.uid);
		synchronized (PercentApplication.localDB) {
			PercentApplication.localDB.insert(Brandlike.TABLE, null, values);
		}
	}

	@Override
	public Brandlike findByBrandId(Long id) {
		Brandlike like = null;
		Cursor c = PercentApplication.localDB.rawQuery("SELECT * FROM "
				+ Brandlike.TABLE + " WHERE id='" + id + "'", null);
		if (c.moveToFirst()) {
			like = new BrandlikeLocal();
			like.brandId = c.getLong(c.getColumnIndex(Brandlike.BRANDID));
			like.id = c.getLong(c.getColumnIndex(Brandlike.ID));
			like.uid = c.getLong(c.getColumnIndex(Brandlike.UID));
		}
		return like;
	}

}
